package com.yanzhiyi.manager.web.controller;

import com.yanzhiyi.user.entity.PageResult;
import com.yanzhiyi.user.entity.Result;
import com.yanzhiyi.user.feign.RoleFeign;
import com.yanzhiyi.user.pojo.Role;
import com.yanzhiyi.user.pojo.SearchCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * FileName: WebRoleController
 * Author:   xuan zongjun
 * Date:     2020/10/22 14:03
 * Description:
 */

@RestController
@CrossOrigin
@RequestMapping("/wrole")
public class WebRoleController {
    @Autowired
    private RoleFeign roleFeign;

    /**
     * 分页和多条件查询
     * @param searchCondition
     * @return
     */
    @PostMapping("/searchPage")
    public Result<PageResult<Role>> searchPage(@RequestBody SearchCondition searchCondition){
        Result<PageResult<Role>> result=  roleFeign.searchPage( searchCondition.getName(),searchCondition.getCurrentPage(),searchCondition.getPageSize());
        return result;
    }

    /**
     * 添加角色
     * @param role
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody  Role role,@RequestParam("menus") Integer [] menus,@RequestParam("permissionIds") Integer [] permissionIds){
        Result result = roleFeign.add( role,menus,permissionIds );
        return result;
    }

    /**
     * 修改角色  使用
     * @param role
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody  Role role,@RequestParam("menus") Integer [] menus,@RequestParam("permissionIds") Integer [] permissionIds){
        return roleFeign.update( role,menus,permissionIds );
    }



    /**
     * 删除角色  使用
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Result delete(Integer id) {
        Result result = roleFeign.delete( id );
        return result;
    }

    /**
     * 根据id 查询角色  使用
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result<Map<String,Object>>  findById(Integer id){
        return roleFeign.findById( id );
    }


    /**
     * 获取所有角色
     * @param
     * @return  角色列表
     */
    @GetMapping("/findAll")
    public Result<List<Role>> findAll(){
        Result<List<Role>> result = roleFeign.findAll();
        return result;
    }












}
